﻿using System;
using System.Collections.Generic;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Xml.Serialization;
using Microsoft.Practices.Modeling.ExtensionProvider.Metadata;
using Microsoft.Practices.Services.ItineraryDsl;
using Microsoft.Practices.Modeling.ExtensionProvider.Extension;
using Microsoft.Practices.Modeling.Common;
using Microsoft.Practices.Modeling.Common.Design;
using Microsoft.Practices.Modeling.Services.Design;
using Microsoft.Practices.Modeling.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
using BizTalk.ESB.Extensions.Helpers;

namespace BizTalk.ESB.Extensions.ResolverExtenders
{
    [Serializable]
    [ObjectExtender(typeof(Resolver))]
    public class StaticServiceProxyRequestResolverExtender : ObjectExtender<Resolver>
    {
        [Category(StaticServiceProxyRequestResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Value of promoted property ServiceName that the service is subscribing to."),
            DisplayName("Service Name"),
            ReadOnly(false),
            Browsable(true)]
        [XmlElement]
        [StringLengthValidator(1, RangeBoundaryType.Inclusive, 0, RangeBoundaryType.Ignore, MessageTemplate = "The 'ServiceName' property should not be null or empty.")]
        public String ServiceName { get; set; }

        [Category(StaticServiceProxyRequestResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Value of promoted property ServiceType that the service is subscribing to."),
            DisplayName("Service Type"),
            ReadOnly(false),
            Browsable(true)]
        [XmlElement]
        public ServiceType ServiceType { get; set; }

        [Category(StaticServiceProxyRequestResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Value of promoted property WCF.Action that the service proxy uses for SOAPAction."),
            DisplayName("Service Action"),
            ReadOnly(false),
            Browsable(true)]
        [XmlElement]
        [StringLengthValidator(1, RangeBoundaryType.Inclusive, 0, RangeBoundaryType.Ignore, MessageTemplate = "The 'ServiceAction' property should not be null or empty.")]
        public String ServiceAction { get; set; }

        [Category(StaticServiceProxyRequestResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Value of promoted property IsRequestResponse that the service is subscribing to."),
            DisplayName("Request Response Service"),
            ReadOnly(false),
            Browsable(true)]
        [XmlElement]
        public Boolean IsRequestResponse { get; set; }


        [Category(StaticServiceProxyRequestResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("BizTalk Map to execute on the message before being sent to the service."),
            DisplayName("Transform Type"),
            ReadOnly(false),
            Editor(typeof(BiztalkTransformTypeEditor), typeof(UITypeEditor)),
            TypeConverter(typeof(TypeConverter)),
            Browsable(true)]
        [XmlElement]
        public String TransformType { get; set; }
    }

    [Serializable]
    [ObjectExtender(typeof(Resolver))]
    public class StaticServiceProxyResponseResolverExtender : ObjectExtender<Resolver>
    {
        [Category(StaticServiceProxyResponseResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Indicates what the input of the response map should be."),
            DisplayName("Response Map Input Option"),
            ReadOnly(false),
            Browsable(true)]
        [XmlElement]
        public MapSourceType ResponseMapInputType { get; set; }

        [Category(StaticServiceProxyResponseResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Indiciates if the context of the original message should be merged with the service response message.  Used only for 2-way.  Response context will override if there are duplicate context keys."),
            DisplayName("Merge Context"),
            ReadOnly(false),
            Browsable(true)]
        [XmlElement]
        public bool MergeContext { get; set; }

        [Category(StaticServiceProxyResponseResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Flag to indicate if the Service Response should be validated."),
            DisplayName("Validate Service Response"),
            ReadOnly(false),
            Browsable(true)]
        [XmlElement]
        public Boolean ValidateResponse { get; set; }

        [Category(StaticServiceProxyResponseResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Type of validation to perform on the Service Response."),
            DisplayName("Validation Method"),
            ReadOnly(false),
            Browsable(true)]
        [XmlElement]
        public ValidationType ValidationMethod { get; set; }

        [EditorOutputProperty("ValidationPolicyVersion", "ValidationPolicyVersion", new String[] { }),
            Category(StaticServiceProxyResponseResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Name of the BRE Policy to execute to validate the response message."),
            DisplayName("Validation BRE Policy Name"),
            ReadOnly(false),
            Browsable(true),
            Editor(typeof(BiztalkPolicyEditor), typeof(UITypeEditor)),
            TypeConverter(typeof(TypeConverter))]
        public String ValidationPolicyName { get; set; }

        [ReadOnly(false),
            DisplayName("Validation Policy Version"),
            Category("Extender Settings"),
            Description("Specifies the policy version"),
            Browsable(true)]
        public VersionNumber ValidationPolicyVersion { get; set; }

        [Category(StaticServiceProxyResponseResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Name of the Document Type for the XML message validated by BRE Policy."),
            DisplayName("Validation BRE Document Type"),
            ReadOnly(false),
            Browsable(true)]
        [XmlElement]
        public String ValidationDocType { get; set; }

        [Category(StaticServiceProxyResponseResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Full path to the file to save BRE Policy execution trace information."),
            DisplayName("Validation BRE Trace File"),
            ReadOnly(false),
            Browsable(true)]
        [XmlElement]
        public String ValidationBreTrace { get; set; }

        [Category(StaticServiceProxyResponseResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Strong Name of the XSD Schema to use to validate the response message."),
            DisplayName("Validation Schema Strong Name"),
            ReadOnly(false),
            Browsable(true)]
        [XmlElement]
        public String ValidationSchemaStrongName { get; set; }

        [Category(StaticServiceProxyResponseResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("BizTalk Map to execute on the message before being returned to the itinerary."),
            DisplayName("Transform Type"),
            ReadOnly(false),
            Editor(typeof(BiztalkTransformTypeEditor), typeof(UITypeEditor)),
            TypeConverter(typeof(TypeConverter)),
            Browsable(true)]
        [XmlElement]
        public String TransformType { get; set; }
    }

    [Serializable]
    [ObjectExtender(typeof(Resolver))]
    public class BreServiceProxyResolverExtender : ObjectExtender<Resolver>
    {
        [EditorOutputProperty("Version", "Version", new String[] { }),
            Category("Extender Settings"),
            Description("Specifies the policy"),
            DisplayName("Policy"),
            ReadOnly(false),
            Browsable(true),
            Editor(typeof(BiztalkPolicyEditor), typeof(UITypeEditor)),
            TypeConverter(typeof(TypeConverter))]
        public String Policy { get; set; }

        [ReadOnly(false),
            DisplayName("Version"),
            Category("Extender Settings"),
            Description("Specifies the policy version"),
            Browsable(true)]
        public VersionNumber Version { get; set; }

        [Description("Used to recognize the Document Type.  Note: This is a messaging only scenario and is not suppored for Orchestration. i.e. - in case of orchestration, the field will always be set to 'false'."),
            DisplayName("Recognize Message Format"),
            Browsable(true),
            ReadOnly(false),
            Category("Extender Settings")]
        public Boolean RecognizeMessageFormat { get; set; }

        [Description("Determines if the message will be sent to the policy as a fact."),
            ReadOnly(false),
            Browsable(true),
            Category("Extender Settings"),
            DisplayName("UseMsg")]
        public Boolean UseMsg { get; set; }
    }
}
